﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;

namespace DesertKharonIrcPlugin
{
    public static class BitmapExtensionMethods
    {
        public static Bitmap Scale(this Bitmap self, float scale)
        {
            int scaleWidth = (int)Math.Ceiling((float)self.Width * scale);
            int scaleHeight = (int)Math.Ceiling((float)self.Height * scale);

            Bitmap scaledBitmap = new Bitmap(scaleWidth, scaleHeight);
            using (Graphics graphics = Graphics.FromImage(scaledBitmap))
            {
                graphics.InterpolationMode = InterpolationMode.High;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.SmoothingMode = SmoothingMode.AntiAlias;

                graphics.Clear(Color.Transparent);
                graphics.DrawImage(self, new Rectangle(0, 0, scaleWidth, scaleHeight));
            }

            return scaledBitmap;
        }
    }
}
